"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Room_1 = __importDefault(require("./Room"));
class Hall {
    constructor() {
        // 连接数
        this.conns = new Map();
    }
    static getInstance() {
        if (this._instance === null) {
            this._instance = new this();
        }
        return this._instance;
    }
    static get instance() {
        return this.getInstance();
    }
    connect(openid, conn) {
        if (!this.conns.has(openid)) {
            this.conns.set(openid, conn);
            conn.openid = openid;
        }
        else {
            const current = this.conns.get(openid);
            if (current != conn) {
                this.conns.set(openid, conn);
                conn.openid = openid;
            }
        }
        Room_1.default.instance.refreshHall();
        return conn;
    }
    unconnect(conn) {
        const openid = conn.openid;
        if (openid) {
            this.remove(openid);
        }
    }
    get(openid) {
        let conn = undefined;
        if (this.conns.has(openid)) {
            conn = this.conns.get(openid);
        }
        return conn;
    }
    lists() {
        return Array.from(this.conns.values());
    }
    remove(openid) {
        this.conns.delete(openid);
        Room_1.default.instance.removeByOpenid(openid);
    }
}
exports.default = Hall;
Hall._instance = null;
